package com.example.getway9001.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.gateway.filter.GatewayFilter;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.factory.AbstractNameValueGatewayFilterFactory;
import org.springframework.cloud.gateway.filter.factory.AddRequestParameterGatewayFilterFactory;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.util.UriComponentsBuilder;
import reactor.core.publisher.Mono;

import java.net.URI;
import java.util.Collections;

@Configuration
@Slf4j
public class RouteConfig {

//    @Bean
//    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
//        return builder.routes()
//                .route("consul_route", r -> r.path("/consul/**")
//                        .uri("lb://consul8889"))
//                .build();
//    }
}

//.filter(new GatewayFilter() {
//@Override
//public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
//        URI uri = exchange.getRequest().getURI();
//        URI newUri = UriComponentsBuilder.fromUri(uri).replaceQuery("id=12345").build(true).toUri();
////                               ServerHttpRequest build = exchange.getRequest().mutate().uri(newUri).build();
//        System.out.println(newUri.toString());
//        ServerWebExchange build1 = exchange.mutate().request(exchange.getRequest().mutate().uri(newUri).build()).build();
//        return chain.filter(build1);
//        }
//        }

